package com.pactera.config;

import com.pactera.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;

import java.io.InputStreamReader;
import java.util.Objects;
import java.util.Properties;

/**
 * Created by 17894 on 2021/3/12.
 */
@Configuration
public class PacteraLoader implements InitializingBean {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private Properties properties;

    public Properties getProperties() {
        return properties;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        InputStreamReader isr = null;
        try {
            isr = new InputStreamReader(PacteraLoader.class.getResourceAsStream(Constant.PROPERTIES_PATH), "utf-8");
            if (Objects.isNull(properties)) {
                properties = new Properties();
            }
            properties.load(isr);
        } catch (Exception e) {
            logger.debug("pactera-app.properties not found");
        } finally {
            if (Objects.nonNull(isr)) {
                isr.close();
            }
        }

    }
}
